package demo1;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 具体装饰器：过滤空字符串单词（含仅空格的单词，需配合去空格使用）
 */
public class FilterEmptyDecorator extends WordReaderDecorator {
    public FilterEmptyDecorator(WordReader wordReader) {
        super(wordReader);
    }

    @Override
    protected List<String> decorate(List<String> words) {
        List<String> nonEmptyWords = words.stream()
                .filter(word -> !word.isEmpty()) // 过滤空字符串
                .collect(Collectors.toList());
        System.out.printf("装饰器-空值过滤：原始%d个单词，过滤后%d个，列表：%s%n",
                words.size(), nonEmptyWords.size(), nonEmptyWords);
        return nonEmptyWords;
    }
}
